// 测试模拟数据和转换函数

// 模拟Article类型数据
const mockArticles = [
  {
    id: 1,
    title: 'React入门指南',
    content: '这是一篇关于React基础知识的入门文章...',
    excerpt: 'React是一个用于构建用户界面的JavaScript库',
    categoryId: 1,
    category: { id: 1, name: '技术' },
    tags: [{ id: 1, name: 'React' }, { id: 2, name: '前端' }],
    viewCount: 123,
    likeCount: 15,
    commentCount: 5,
    authorId: 1,
    author: { id: 1, username: 'admin', avatar: 'https://randomuser.me/api/portraits/men/1.jpg' },
    type: 'tech',
    status: 'published',
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-01T00:00:00Z'
  },
  {
    id: 2,
    title: 'TypeScript进阶技巧',
    content: 'TypeScript提供了强大的类型系统...',
    excerpt: '掌握这些TypeScript技巧，让你的代码更加健壮',
    categoryId: 1,
    category: { id: 1, name: '技术' },
    tags: [{ id: 3, name: 'TypeScript' }, { id: 2, name: '前端' }],
    viewCount: 98,
    likeCount: 8,
    commentCount: 2,
    authorId: 2,
    author: { id: 2, username: 'user1', avatar: 'https://randomuser.me/api/portraits/women/2.jpg' },
    type: 'tech',
    status: 'published',
    createdAt: '2024-01-02T00:00:00Z',
    updatedAt: '2024-01-02T00:00:00Z'
  }
];

// 模拟转换函数
function convertToBlogPost(article) {
  return {
    id: article.id,
    title: article.title,
    excerpt: article.excerpt || article.content.substring(0, 150) + '...',
    author: article.author?.username || '未知作者',
    date: new Date(article.createdAt).toISOString().split('T')[0],
    category: article.category?.name || '未分类',
    tags: article.tags?.map(tag => tag.name) || [],
    image: article.coverImage || 'https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixlib=rb-1.2.1&q=80&w=1080',
    readTime: Math.ceil((article.content?.length || 0) / 500) + '分钟阅读'
  };
}

// 执行转换
console.log('开始测试模拟数据转换...');
console.log('原始模拟数据数量:', mockArticles.length);

const blogPosts = mockArticles.map(convertToBlogPost);
console.log('转换后的blogPosts数量:', blogPosts.length);
console.log('转换后的blogPosts:', JSON.stringify(blogPosts, null, 2));

// 验证每个字段
blogPosts.forEach((post, index) => {
  console.log(`\n文章 ${index + 1}:`);
  console.log(`ID: ${post.id}`);
  console.log(`标题: ${post.title}`);
  console.log(`作者: ${post.author}`);
  console.log(`日期: ${post.date}`);
  console.log(`分类: ${post.category}`);
  console.log(`标签: ${post.tags.join(', ')}`);
});

console.log('\n测试完成！');